﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace HFUTCourseSimulation.Util {
    public static class Win32Dialog {

        /// <summary>
        /// 打开学期存档文件
        /// </summary>
        /// <returns>如果用户选定了文件，返回文件路径，否则返回null</returns>
        public static string OpenSemester() {
            Microsoft.Win32.OpenFileDialog op = new Microsoft.Win32.OpenFileDialog();
            op.RestoreDirectory = true;
            op.Multiselect = false;
            op.Filter = "学期课程存档文件(*.json)|*.json|所有文件(*.*)|*.*";
            var status = op.ShowDialog();
            if (!(status.HasValue && status.Value)) return null;
            else return op.FileName;
        }

        /// <summary>
        /// 保存学期存档文件
        /// </summary>
        /// <returns>如果用户选定了文件，返回文件路径，否则返回null</returns>
        public static string SaveSemester() {
            var sp = new Microsoft.Win32.SaveFileDialog();
            sp.RestoreDirectory = true;
            sp.Filter = "学期课程存档文件(*.json)|*.json|所有文件(*.*)|*.*";
            var status = sp.ShowDialog();
            if (!(status.HasValue && status.Value)) return null;
            else return sp.FileName;
        }

        /// <summary>
        /// 保存渲染的学期图片文件
        /// </summary>
        /// <returns>如果用户选定了文件，返回文件路径，否则返回null</returns>
        public static string SaveRender() {
            var sp = new Microsoft.Win32.SaveFileDialog();
            sp.RestoreDirectory = true;
            sp.Filter = "图片文件(*.png)|*.png|所有文件(*.*)|*.*";
            var status = sp.ShowDialog();
            if (!(status.HasValue && status.Value)) return null;
            else return sp.FileName;
        }

        /// <summary>
        /// 颜色选择框
        /// </summary>
        /// <returns>如果用户选择颜色并点击了确定，则返回用户选择的颜色，否则返回null</returns>
        public static Color? PickColor() {
            var picker = new System.Windows.Forms.ColorDialog();
            var rv = picker.ShowDialog();
            if (rv != System.Windows.Forms.DialogResult.OK) return null;
            else return ColorTrans.ToWpfColor(picker.Color);
        }

        /// <summary>
        /// 显示一个经典的Windows错误对话框
        /// </summary>
        public static void Error(string message, string caption) {
            MessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
        }

        /// <summary>
        /// 显示一个经典的Windows信息对话框
        /// </summary>
        public static void Info(string message, string caption) {
            MessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
        }

        /// <summary>
        /// 显示一个经典的Windows确认操作对话框
        /// </summary>
        /// <returns>如果用户点击了确认，则返回true，否则返回false</returns>
        public static bool Confirm(string message, string caption) {
            var rv = MessageBox.Show(message, caption, MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel);
            return rv == MessageBoxResult.OK;
        }

    }
}
